package com.yanchangapp.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

import com.haibin.calendarview.CalendarLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

/**
 * Created by apple on 2019-11-06.
 * description:
 */
public class NiceSmartRefreshLayout extends SmartRefreshLayout {
    private float mStartX;
    private float mStartY;
    private CalendarLayout mCalendarLayout;

    public void setCalendarLayout(CalendarLayout calendarLayout) {
        mCalendarLayout = calendarLayout;
    }

    public NiceSmartRefreshLayout(Context context) {
        super(context);
    }

    public NiceSmartRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NiceSmartRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                mStartX = ev.getRawX();
                mStartY = ev.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                float endY = ev.getRawY();
                float endX = ev.getRawX();
                float x = endX - mStartX;
                float y = endY - mStartY;
                /* 上下滑动拦截*/
                if (Math.abs(y) > Math.abs(x))
                {
                    if (y > 0 && mCalendarLayout.isExpand() && !mCalendarLayout.canScrollVertically(-1)){
                        // 如果上下滑动 且不能再滑动了就拦截
                        Log.e("滑动", "不能再滑动了" );
                        return true;
                    }else {
                        return false;
                    }
                }
                break;

        }
        return super.onInterceptTouchEvent(ev);
    }
}
